// Copyright (c) 2024, lanlian and contributors
// For license information, please see license.txt

frappe.ui.form.on("Server Config", {
	refresh(frm) {
        if (!cur_frm.is_new()) {
			frm.add_custom_button(__('测试连接'), () => {
				frm.call({
					method: 'ems.equipment_managerment_system.doctype.server_config.server_config.login_validate',
					args: {
						server_url: frm.doc.server_url, 
						acctid: frm.doc.acctid, 
						user_name: frm.doc.user_name, 
						user_password: frm.doc.user_password,
					},
				}).then((r) => {	
					frappe.msgprint(r.message)
					// console.log(r.message)
				})
			})
		}
	},
	disable: function(frm) {	
		if (frm.doc.disable==1){
			frappe.confirm('请确认要禁用该服务器?与ERP交互的接口地址将切换/停止',
			() => {
				// action to perform if Yes is selected
			}, () => {
				frm.set_value('disable', 0)
				frm.refresh_field('disable')		
			})
		}	

	},
});
